/* 1videoConference -- An open source video conferencing platform.
* Copyright (C) 2007 - 2008, Adiance Technologies Pvt. Ltd.
*
* Hardik Sanghvi <hardik.sanghvi @adiance.com>
*
* See http://www.1videoconference.org for more information about
* the 1videoConference project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, forums and mailing lists
* for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
********************************************************************************/

using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.Reflection;
using Adiance.VMukti.DAL;
using System.Windows;

namespace Adiance.VMukti.BAL
{
    public class CliUriInfo
    {
        NetPeerService.NetPeerClient npcUriInfo = null;
        object objUriInfo = new svcUriInfo();
        IsvcUriInfoChannel svcUriInfo;

        System.Threading.Thread servClient;

        string ServerIPAddr = "";

        public CliUriInfo(string MainServiceURI)
        {
            ServerIPAddr = MainServiceURI.Replace("net.tcp://", "").Split(':')[0];
            servClient = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(RegClient));
            try
            {
                servClient.Start(MainServiceURI);
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "Adiance.VMukti.VCServer--:--CliUriInfo.cs--:--CliUriInfo()--:--");
                Adiance.VMukti.BAL.clsUtility.LogException = exp;
                //MessageBox.Show(exp.Message);
            }
        }

        void RegClient(object MainServiceURI)
        {
            try
            {
                ((svcUriInfo)objUriInfo).EntsvcJoin += new svcUriInfo.DelsvcJoin(CliUriInfo_EntsvcJoin);
                ((svcUriInfo)objUriInfo).EntsvcGetDbCred += new svcUriInfo.DelsvcGetDbCred(CliUriInfo_EntsvcGetDbCred);
                ((svcUriInfo)objUriInfo).EntsvcSetDbCred += new svcUriInfo.DelsvcSetDbCred(CliUriInfo_EntsvcSetDbCred);
                ((svcUriInfo)objUriInfo).EntsvcGetUri += new svcUriInfo.DelsvcGetUri(CliUriInfo_EntsvcGetUri);
                ((svcUriInfo)objUriInfo).EntsvcSetUri += new svcUriInfo.DelsvcSetUri(CliUriInfo_EntsvcSetUri);
                ((svcUriInfo)objUriInfo).EntsvcUnJoin += new svcUriInfo.DelsvcUnJoin(CliUriInfo_EntsvcUnJoin);


                npcUriInfo = new NetPeerService.NetPeerClient();
                svcUriInfo = (IsvcUriInfoChannel)npcUriInfo.OpenClient<IsvcUriInfoChannel>(MainServiceURI.ToString(), "UriInfoMesh", ref objUriInfo);
                svcUriInfo.svcJoin();
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "Adiance.VMukti.VCServer--:--CliUriInfo.cs--:--RegClient()--:--");
                Adiance.VMukti.BAL.clsUtility.LogException = exp;
                //clsException.LogError(exp);
                //MessageBox.Show(exp.Message);
            }
        }

        void CliUriInfo_EntsvcJoin()
        {
        }

        void CliUriInfo_EntsvcGetDbCred(string uname)
        {
            try
            {
                string[] DBCredentials = new string[3];
                DBCredentials[0] = UserInfo.ConSitePath.Replace("http://", "").Split('/')[0];
                DBCredentials[1] = UserInfo.strDBUser;
                DBCredentials[2] = UserInfo.strDBPass;

                svcUriInfo.svcSetDbCred(uname, DBCredentials);
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "Adiance.VMukti.BAL--:--CliUriInfo.cs--:--CliUriInfo_EntsvcGetDbCred()--:--");
                Adiance.VMukti.BAL.clsUtility.LogException = exp;
                //System.Windows.MessageBox.Show("GetDatabaseCred" + exp.Message);
            }
        }

        void CliUriInfo_EntsvcSetDbCred(string uname, string[] cred)
        {

        }

        void CliUriInfo_EntsvcGetUri(string uname,string meetingid)
        {
            try
            {
                string[] strServiceUri = UserServices.GetUri(meetingid);
                svcUriInfo.svcSetUri(uname, strServiceUri);
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "Adiance.VMukti.BAL--:--CliUriInfo.cs--:--CliUriInfo_EntsvcGetUri()--:--");
                Adiance.VMukti.BAL.clsUtility.LogException = exp;
                //System.Windows.MessageBox.Show("GetUri" + exp.Message);                
            }
        }

        void CliUriInfo_EntsvcSetUri(string uname,string[] uriarray)
        {

        }

        void CliUriInfo_EntsvcUnJoin()
        {
        }
    }
}
